package com.wl.lib.mvi

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.wl.lib.utils.ResUtils
import com.wl.lib.utils.StatusBarMode
import com.wl.lib.utils.StatusBarUtils
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode


// Created by wangliang on 2024/4/24.
abstract class BaseActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
        if (!isFullscreen()) {
            initStatusBar()
        }
    }

    override fun onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
        super.onDestroy()
    }

    private fun initStatusBar() {
        val statusBarColor = if (transparentStatusBar()) {
            ResUtils.getColor(android.R.color.transparent)
        } else {
            ResUtils.getColor(android.R.color.white)
        }
        StatusBarUtils.initStatusBar(this, transparentStatusBar(), statusBarColor, StatusBarMode.MODE_LIGHT)
    }

    /**
     * 是否要绘制系统状态栏下方区域，默认为false，由基类来添加paddingView并设置与导航栏同样颜色来实现透明状态栏
     */
    open fun transparentStatusBar(): Boolean = false

    /**
     * 是否是全屏页面，如果是，将不会不对状态栏做任何改动
     */
    open fun isFullscreen(): Boolean = false

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onLogoutEvent(event: OnLogoutEvent) {
        finish()
    }
}

class OnLogoutEvent()
